import moment from "moment";

const formItemLayout = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 8 }
  }
};

const workTimeClassify = (workTime, startTime, endTime) => {
  if (workTime === 1) {
    return {
      startTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment()
        .add(101, "years")
        .format("YYYY-MM-DD HH:mm:ss")
    };
  }
  if (workTime === 2) {
    return {
      startTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment()
        .add(1, "years")
        .format("YYYY-MM-DD HH:mm:ss")
    };
  }
  if (workTime === 3) {
    return {
      startTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment()
        .add(1, "months")
        .format("YYYY-MM-DD HH:mm:ss")
    };
  }
  if (workTime === 4) {
    return {
      startTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment()
        .add(1, "weeks")
        .format("YYYY-MM-DD HH:mm:ss")
    };
  }
  if (workTime === 5) {
    return {
      startTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment()
        .format("YYYY-MM-DD")
        .concat(" 23:59:59")
    };
  }
  return { startTime, endTime };
};

const setWork = detailMessage => {
  if (detailMessage && detailMessage !== {}) {
    if (detailMessage.sourceType || detailMessage.sourceType === 0) {
      return { workTime: Number(detailMessage.sourceType) };
    }
    const startTime = moment(detailMessage.startTime).format(
      "YYYY-MM-DD HH:mm:ss"
    );
    const endTime = moment(detailMessage.endTime).format("YYYY-MM-DD HH:mm:ss");
    if (
      moment(endTime, "YYYY-MM-DD HH:mm:ss").diff(
        moment(startTime, "YYYY-MM-DD HH:mm:ss"),
        "years"
      ) >= 100
    ) {
      return { workTime: 1 };
    }
    if (
      moment(endTime, "YYYY-MM-DD HH:mm:ss").diff(
        moment(startTime, "YYYY-MM-DD HH:mm:ss"),
        "weeks"
      ) === 1
    ) {
      return { workTime: 4 };
    }
    if (
      moment(endTime, "YYYY-MM-DD HH:mm:ss").diff(
        moment(startTime, "YYYY-MM-DD HH:mm:ss"),
        "years"
      ) === 1
    ) {
      return { workTime: 2 };
    }
    if (
      moment(endTime, "YYYY-MM-DD HH:mm:ss").diff(
        moment(startTime, "YYYY-MM-DD HH:mm:ss"),
        "days"
      ) < 1
    ) {
      return { workTime: 5 };
    }
    if (
      moment(endTime, "YYYY-MM-DD HH:mm:ss").diff(
        moment(startTime, "YYYY-MM-DD HH:mm:ss"),
        "months"
      ) === 1
    ) {
      return { workTime: 3 };
    }
  }
  return {
    workTime: 6
  };
};

export default { formItemLayout, workTimeClassify, setWork };
